<template>
  <div class="posReport">
    <CommonBtn label-name="LKA POS门店清单报告管理" v-if="!button || (button.event!='add()' && button.event!='edit()') " :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked">{{item.label+":"+(item.type=='search'?item.proxy:item.value)}}</span>
    </CommonBtn>
    <CommonList ref="list" v-if="!button || (button.event!='add()' && button.event!='edit()')" :buttons="buttons"
                :columns="columns" :listUrl="listUrl" @tableSelect="tableSelect"  :conditions="conditions"></CommonList>
    <search-pop-up :out-btn="button"
                   :props="columns" @close="close"
                   :out-conditions="conditions"
                   @conditionChange="conditionChange"></search-pop-up>
    <CommonExport :out-btn="button" :props="columns"
                  @close="close" :export-url="$api.API_LKAPOSRETAILERLIST_EXPORT" :conditions="conditions"></CommonExport>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList";
    import CommonBtn from "../../common/CommonBtn";
    import SearchPopUp from "../../common/SearchPopUp";
    import CommonExport from "../../common/CommonExport";
    import moment from 'moment';
    export default {
        name:'posReport',
        data(){
            return{
                nowTime: new Date(),
                year:0,
                buttons:[
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH
                ],
                columns:[
                    {
                        prop:'retailGroupName',
                        label:'集团客户名称',
                        label1:'集团客户名称',
                        search:true,
                        type:'search',
                        searchUrl:this.$api.API_SELECT_CUSTOMER_GROUP_INFO,
                        searchLabel:'客户集团',
                        searchProxy:'customNameCN',
                        searchValue:'pkid',
                        proxy:'customNameCN',
                        queryProp:'fkRetailGroup',
                        columns:[
                            {
                                prop:'customCode',
                                label:'客户集团编码',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'customNameCN',
                                label:'集团中文名称',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'customNameEN',
                                label:'集团英文名称',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'accountCode',
                                label:'预算Account',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'customTypeName',
                                label:'集团分类',
                                search:true,
                                type:'search',
                                columns:[
                                    {
                                        prop:'customTypeCode',
                                        label:'集团类型编码',
                                        search:true,
                                        type:'text'
                                    },
                                    {
                                        prop:'customTypeName',
                                        label:'集团类型名称',
                                        search:true,
                                        type:'text'
                                    },
                                    {
                                        prop:'valid',
                                        label:'是否有效',
                                        search:true,
                                        type:'checkbox'
                                    }
                                ],
                                searchUrl:this.$api.API_CUSTOMERCLASSIFY_LIST,
                                searchLabel:'客户集团分类',
                                searchProxy:'customTypeCode',
                                searchValue:'pkid',
                                queryProp:'fkCustomType'
                            },
                            {
                                prop:'isValid',
                                label:'是否有效',
                                search:true,
                                type:'checkbox'
                            }
                        ]
                    },
                    {
                        prop:'storeCode',
                        label:'POS端门店代码',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'tpwfCode',
                        label:'TPWF代码',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'cdccCode',
                        label:'统一代码',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'isSfa',
                        label:'是否覆盖SFA（是或否）',
                        search:true,
                        type:'radio',
                        radioColumns:[
                            {
                                label:'是',
                                value:'1',
                            },{
                                label:'否',
                                value:'0',
                            }
                        ],
                        queryProp:'isSfa',
                        searchValue:'value'
                    },
                    {
                        prop:'retailName',
                        label:'POS端门店名称',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'city',
                        label:'CITY（必须在656个城市范围内）',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop:'provinceName',
                                label:'所属省份',
                                search:false,
                                type:'text'
                            },
                            {
                                prop: 'cityCode',
                                label: '城市编码',
                                type:'text',
                                search:true
                            },{
                                prop: 'cityName',
                                label: '城市名称',
                                type:'text',
                                search:true
                            },{
                                prop: 'isValid',
                                label: '是否有效'
                            }
                        ],
                        searchUrl:this.$api.API_QUERYCITY,
                        searchLabel:'城市信息',
                        proxy:'cityName',
                        searchProxy:'cityName',
                        queryProp:'fkCity',
                        searchValue:'pkid'
                    },
                    {
                        prop:'posRetailerType',
                        label:'门店类型',
                        search:false,
                        type:'text'
                    },
                    {
                        prop:'supplyType',
                        label:'Supply Type',
                        search:true,
                        type:'radio',
                        radioColumns:[
                            {
                                label:'Direct',
                                value:'Direct',
                            },{
                                label:'Indirect',
                                value:'Indirect',
                            }
                        ],
                        queryProp:'supplyType',
                        searchValue:'value',
                        proxy:'levelName',
                        searchProxy:'levelName',
                    },
                    {
                        prop:'soldToCode',
                        label:'经销商代码',
                        search:false,
                        type:'text'
                    },
                    {
                        prop:'soldToName',
                        label:'经销商名称',
                        search:false,
                        type:'text'
                    },
                    {
                        prop:'storePyramid',
                        label:'Store Pyramid',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop:'levelCode',
                                label:'门店投资属性编码'
                            },
                            {
                                prop: 'levelName',
                                label: '门店投资属性名称'
                            }
                        ],
                        searchUrl:this.$api.API_SELECT_RETAIL_LEVEL_INFO,
                        searchLabel:'门店投资属性',
                        proxy:'levelName',
                        searchProxy:'levelName',
                        queryProp:'fkLevel',
                        searchValue:'pkid'
                    },
                    {
                        prop:'remark1',
                        label:'备用字段一',
                        search:false,
                        type:'text'
                    },
                    {
                        prop:'remark2',
                        label:'备用字段二',
                        search:false,
                        type:'text'
                    },
                    {
                        prop:'remark3',
                        label:'备用字段三',
                        search:false,
                        type:'text'
                    },
                    {
                        prop:'re',
                        label:'RE',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop:'retailCode',
                                label:'门店类型编码'
                            },
                            {
                                prop: 'retailName',
                                label: '门店类型名称'
                            }
                        ],
                        searchUrl:this.$api.API_SELECT_RETAIL_TYPE_INFO,
                        searchLabel:'门店类型',
                        proxy:'retailName',
                        searchProxy:'retailName',
                        queryProp:'fkRetailType',
                        searchValue:'pkid'
                    },
                    {
                        prop:'location',
                        label:'Location',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop:'locationCode',
                                label:'LocationCode'
                            },
                            {
                                prop: 'locationName',
                                label: 'LocationName'
                            }
                        ],
                        searchUrl:this.$api.API_COMMON_LOCATION_INFO,
                        searchLabel:'门店类型',
                        proxy:'locationName',
                        searchProxy:'locationName',
                        queryProp:'fkLocation',
                        searchValue:'pkid'
                    },
                    {
                        prop:'sfaCode',
                        label:'SFACode',
                        search:true,
                        type:'text'
                    },
                ],
                listUrl:this.$api.API_SELECT_LKAPOSRETAILER_LIST,
                button:{},
                conditions:[],
                row:{}
            }
        },
        created() {
           this.getYear()
        },
        methods:{
            onButtonClick(item) {
                this.button = item
            },
            tableSelect(row) {
                this.row = row
            },
            conditionChange(conditions) {
                this.$refs.list.search()
            },
            close(item) {
                this.button = item
            },
            getYear(){
               this.year=this.nowTime.getFullYear();
               var lastyear=this.year-1;
               for(let item of this.columns){
                   if (item.prop=='areaName') {
                       item.label=this.year+' Area';
                       item.label1=this.year+' Area'
                   }
                   if (item.prop=='regionName') {
                       item.label=this.year+' Region';
                       item.label1=this.year+' Region'
                   }
                   if (item.prop=='oldAreaName') {
                       item.label=lastyear+' AREA';
                       item.label1=lastyear+' AREA'
                   }
                   if (item.prop=='oldRegionName') {
                       item.label=lastyear+' Region';
                       item.label1=lastyear+' Region'
                   }
               }
            }
        },
        components:{CommonExport, SearchPopUp,CommonList,CommonBtn}
    }
</script>
